import {Ref, ref} from "vue";
import {getCourseZSDetail} from "../../api/classes";
import {FetchCourseZSDetailDAT} from "../../types/responseTypes";
import {useStore} from "vuex";

export function useCourseZSDetail(){

    const courseZSDetail = ref({}) as Ref<FetchCourseZSDetailDAT>

    const {state} = useStore()
    function initCourseZSDetail(CLASS_ID: string){
        return getCourseZSDetail({
            CLASS_ID,
            OPERATOR_ID: state.user.userInfo.CUSER_ID
        }).then(res => {
            if (res.ERROR[0].errcode == '0'){
                courseZSDetail.value = res.DAT[0]
            }else {
                uni.showToast({
                    title: res.ERROR[0].error,
                    icon: 'none',
                    mask: true
                })
            }
        }).catch(err => {
            uni.showToast({
                title: '获取信息失败',
                icon: 'error',
                mask: true
            })
        })
    }

    return {
        courseZSDetail,
        initCourseZSDetail
    }
}
